package com.github.iot.dao;

import android.content.Context;

import com.github.iot.entity.SystemSetting;

import java.util.List;

/**
 * TODO
 *
 * @Author: 梁声洪
 * @Date: 2019/12/7 13:45
 * @Version: v1.0.0
 */
public class SystemSettingDaoUtils {

    private DaoManager mManager;

    public SystemSettingDaoUtils(Context context) {
        mManager = DaoManager.getInstance();
        mManager.init(context);
    }

    public boolean insertSetting(SystemSetting setting) {
        return mManager.getDaoSession().getSystemSettingDao().insert(setting) == -1 ? false : true;
    }

    public boolean updateSetting(SystemSetting setting) {
        boolean flag = false;
        try {
            mManager.getDaoSession().update(setting);
            flag = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

    /**
     * 查询所有记录
     *
     * @return
     */
    public SystemSetting querySetting() {
        List<SystemSetting> list = mManager.getDaoSession().loadAll(SystemSetting.class);
        if (list != null) {
            return list.get(0);
        }
        return null;
    }

    /**
     * 根据主键id查询记录
     *
     * @param key
     * @return
     */
    public SystemSetting querySettingById(long key) {
        return mManager.getDaoSession().load(SystemSetting.class, key);
    }

}